package com.fubowen.reader.db.bean

import android.view.View
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import com.fubowen.reader.R
import com.fubowen.reader.adapter.ISimple
import com.fubowen.reader.databinding.PublicCollectorItemBinding
import com.fubowen.reader.databinding.PublicTreeFilterItemBinding

@Entity(indices = [Index(value = ["webSiteId"], unique = true)])
class WebSiteConfigBean @JvmOverloads constructor(
    var label: String = "",
    var key: String = "",
    var value: String = "",
    var hint: String = "",
    var description: String = "",
    var webSiteId: Int = 0,
    @PrimaryKey(autoGenerate = true)
    var id: Int = 0,
    var timestamp: Long = System.currentTimeMillis()
) : ISimple<WebSiteConfigBean> {
    override fun isSame(new: WebSiteConfigBean) = webSiteId == new.webSiteId && value == new.value

    override fun isSameOfContent(new: WebSiteConfigBean) = webSiteId == new.webSiteId && value == new.value

    override fun onBind(view: View, id: Int) = when (id) {

        R.layout.public_collector_item -> {
            val binding = PublicCollectorItemBinding.bind(view)
            binding.label.text = this.label
            binding.value.setText(value)
            binding.value.hint = hint
        }

        R.layout.public_tree_filter_item -> {
            val binding = PublicTreeFilterItemBinding.bind(view)
            binding.label.text = label
            binding.value.text = value
            binding.description.text = description
        }

        else -> {}
    }
}